cmake_minimum_required(VERSION 3.0.0)
project(HSMD VERSION 0.1.0)

SET(CMAKE_CXX_STANDARD 17)
# 解决执行程序打印的中文乱码问题
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -finput-charset=UTF-8 -fexec-charset=UTF-8")


# SET(CMAKE_BUILD_TYPE Debug)
SET(CMAKE_BUILD_TYPE RelWithDebInfo)
#SET(CMAKE_BUILD_TYPE Release)

############################################################
MESSAGE("################ HSMD ##############")
MESSAGE(${CMAKE_SYSTEM_NAME})
MESSAGE(${CMAKE_BUILD_TYPE})
STRING(TIMESTAMP BUILDTIME "%Y-%m-%d %H:%M:%S")
MESSAGE(${BUILDTIME})

SET(PROJECT_ROOT_DIR ${PROJECT_SOURCE_DIR})
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH "\${ORIGIN}/libs")

IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
    ADD_DEFINITIONS("-fPIC -Wall -fpermissive")
    INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
    LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/libs)

    IF (CMAKE_BUILD_TYPE MATCHES "Release")
        ADD_DEFINITIONS("-O3")# -mavx2 -msse -msse2 -msse3 -mmmx -m3dnow -march=native -mtune=native -m64"
        file(MAKE_DIRECTORY ${PROJECT_SOURCE_DIR}/out/linux/Release)
        set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/out/linux/Release)
        file(MAKE_DIRECTORY ${PROJECT_SOURCE_DIR}/out/linux/Release/libs)
        set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/out/linux/Release/libs)
        file(COPY  ${PROJECT_ROOT_DIR}/libs/*.so DESTINATION ${LIBRARY_OUTPUT_PATH})

    ELSEIF (CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
        file(MAKE_DIRECTORY ${PROJECT_SOURCE_DIR}/out/linux/RelWithDebInfo)
        set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/out/linux/RelWithDebInfo)
        file(MAKE_DIRECTORY ${PROJECT_SOURCE_DIR}/out/linux/RelWithDebInfo/libs)
        set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/out/linux/RelWithDebInfo)
        file(COPY  ${PROJECT_ROOT_DIR}/libs/libHsFutuSystemInfo.so DESTINATION ${LIBRARY_OUTPUT_PATH})
        file(COPY  ${PROJECT_ROOT_DIR}/libs/libHSMdApi.so DESTINATION ${LIBRARY_OUTPUT_PATH})
        file(COPY  ${PROJECT_ROOT_DIR}/libs/libHSTradeApi.so DESTINATION ${LIBRARY_OUTPUT_PATH})
        file(COPY  ${PROJECT_ROOT_DIR}/libs/libt2sdk.so DESTINATION ${LIBRARY_OUTPUT_PATH})
        file(COPY  ${PROJECT_ROOT_DIR}/libs/libtcpsdk.so DESTINATION ${LIBRARY_OUTPUT_PATH})

    ELSEIF (CMAKE_BUILD_TYPE MATCHES "Debug")
        ADD_DEFINITIONS("-D_DEBUG -O0 -ggdb")
        file(MAKE_DIRECTORY ${PROJECT_SOURCE_DIR}/out/linux/Debug)
        set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/out/linux/Debug)
        file(MAKE_DIRECTORY ${PROJECT_SOURCE_DIR}/out/linux/Debug/libs)
        set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/out/linux/Debug/libs)
        file(COPY  ${PROJECT_ROOT_DIR}/libs/*.so DESTINATION ${LIBRARY_OUTPUT_PATH})

    ENDIF ()

ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
    MESSAGE(FATAL_ERROR "NOT SUPPORT WINDOWS")
ENDIF ()

###########################################
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/libs)

SET(HSTMD_SOURCE_FILES
		${PROJECT_SOURCE_DIR}/HstMD.cpp
        ${PROJECT_SOURCE_DIR}/Md.cpp
        ${PROJECT_SOURCE_DIR}/public.cpp
        ${PROJECT_SOURCE_DIR}/EncodingConvertor.cpp
        )
ADD_EXECUTABLE(HstMD ${HSTMD_SOURCE_FILES})


SET(HSTTD_SOURCE_FILES
		${PROJECT_SOURCE_DIR}/HstTD.cpp
        ${PROJECT_SOURCE_DIR}/Trade.cpp
        ${PROJECT_SOURCE_DIR}/public.cpp
        ${PROJECT_SOURCE_DIR}/EncodingConvertor.cpp
        )
ADD_EXECUTABLE(HstTD ${HSTTD_SOURCE_FILES})

TARGET_LINK_LIBRARIES(HstMD libtcpsdk.so libt2sdk.so libHsFutuSystemInfo.so libHSMdApi.so rt pthread -Wl,-rpath,'$ORIGIN'/libs)
TARGET_LINK_LIBRARIES(HstTD libtcpsdk.so libt2sdk.so libHsFutuSystemInfo.so libHSTradeApi.so rt pthread -Wl,-rpath,'$ORIGIN'/libs)
